﻿using System;
using System.Collections.Generic;
using System.Text;

namespace csharpcore7_ch3
{
    class NestedExample1
    {
        static void _Main()
        {
           // 从外层类以访问嵌套类型，需要使用外层类名进行限定（就像访问静态成员一样）
           TopLevel.Color color = TopLevel.Color.Red;

            //在外层类型之外的类型中引用嵌套类型
           TopLevel.Nested n = new TopLevel.Nested();
        }
    }

    public class TopLevel
    {
        static int x;
        public class Nested 
        {
            //在嵌套类型中访问外层私有成员
            protected static void Foo() { Console.WriteLine(TopLevel.x); }
        }                 //Nested class
        public enum Color { Red,Blue,Tan}   //Nested enum
    }

    //在嵌套类型上使用protected访问权限修饰符
    public class SubTopLevel : TopLevel
    {
        static void Foo() {
            new TopLevel.Nested();
        }
    }
}
